/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Serveur;

/**
 *
 * @author Florian MININ & Khémon BEH
 */
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.util.Properties;
import java.util.ResourceBundle;

	
public class RemoteResourcesImpl extends UnicastRemoteObject implements RemoteResources {
	
    private Properties donnees = null;

    public RemoteResourcesImpl() throws RemoteException {
            super();
            // static resources initialization
            donnees = new Properties();
    }
	
    @Override
    public void setValue(String key, Object value) throws RemoteException {
        donnees.put(key, value);
    }

    @Override
    public Object getValue(String key) throws RemoteException {
        return donnees.getProperty(key);
    }

    
    @Override
    public double calculAnnuite(double montant, double txInteret, double nbAnnees) throws RemoteException {
        txInteret = txInteret / 100;
        double puissance = Math.pow(1 + txInteret, nbAnnees);
        return montant * txInteret * (puissance / (puissance - 1));
    }

    @Override
    public double calculNbAnnees(double montant, double txInteret, double annuite) throws RemoteException {
        txInteret = txInteret / 100;
        double numerateur = Math.log(1 - ((txInteret * montant) / annuite));
        double denominateur = Math.log(1 + txInteret);
        return -(numerateur / denominateur);
    }

    public static void main(String[] argv){
        // Create and install a security manager
	if (System.getSecurityManager() == null) {
	    System.setSecurityManager(new RMISecurityManager());
	}
	try {
		RemoteResourcesImpl obj = new RemoteResourcesImpl ();
	
		// Bind this object instance to the name "RemoteServer"
                String name = ResourceBundle.getBundle("Serveur.config").getString("name");
		Naming.rebind(name, obj);
	
		System.out.println("RemoteServer bound in registry");

	} catch (Exception e) {
	  System.out.println("RemoteResourcesImpl err: " + e.getMessage());
	  e.printStackTrace();
	}
    }

}
